package com.example.springmvcuse;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

@RestController
@RequestMapping("/book")
public class BookController {
    @RequestMapping("/getList")
    public List<bookInfor> getList(){
        List<bookInfor> books = mockData();
        for(bookInfor book: books){
            if(book.getStatus()==1){
                book.setStatusCN("可借阅");
            }else{
                book.setStatusCN("不可借阅");
            }
        }
        return books;
    }

    public List<bookInfor> mockData(){
        List<bookInfor>books = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            bookInfor book = new bookInfor();
            book.setId(i);
            book.setBookName("书名"+i);
            book.setAuthor("作者"+i);
            book.setCount(i*5+3);
            book.setPrice(new BigDecimal(new Random().nextInt(100)));
            book.setPublish("出版社"+i);
            book.setStatus(1);
            books.add(book);
        }
        return books;
    }

}
